package ActionStatus;

our ($success, $failure, $cant_do, $impossible, $done, $quit);

$quit = {NAME=>"QUIT"};

$success = {NAME=>"SUCCESS"};
    $done          = {NAME=>"DONE", PARENT=>$success};



$failure = {NAME=>"FAILURE"};
    $cant_do    = {NAME=>"CANT_DO", PARENT=>$failure};
    $impossible = {NAME=>"IMPOSSIBLE", PARENT=>$failure};
    $silent_ignore = {NAME=>"SILENT_IGNORE", PARENT=>$failure};
    $dead = {NAME=>"DEAD", PARENT=>$failure};
    $cell_occupied = {NAME=>"CELL_OCCUPIED", PARENT=>$failure};

our %status_names = (
    SUCCESS   =>$success,
    FAILURE   =>$failure,
    CANT_DO   =>$cant_do,
    IMPOSSIBLE=>$impossible,
    DONE      =>$done,
    QUIT      =>$quit,
    SILENT_IGNORE => $silent_ignore,
    DEAD => $dead,
    CELL_OCCUPIED => $cell_occupied
    );

our $getStatus =  sub{
    my $statusName = shift;

    my $status = $status_names{$statusName};
    my $result = undef;
    while(defined($status)){
	$result = {NAME=>$statusName} unless(defined($result));
	
	$result->{$status->{NAME}} = 1;
	$status = $status->{PARENT};
    }

    return $result;
};


sub new{
    my $class = shift;
    my $statusName = shift;
    my $self = &$getStatus($statusName);

    bless $self, $class;
    return $self;
}

sub is{
    my $self = shift;
    my $statusName = shift;

    return (exists($self->{$statusName}));
}

sub name{
    my $self = shift;
    return $self->{NAME};
}
